<?php

use App\Events\TestEvent;
use App\Facades\SN;
use App\Http\Controllers\CampusController;
use App\Http\Controllers\CardController;
use App\Http\Controllers\ClassMemberController;
use App\Http\Controllers\ClasssController;
use App\Http\Controllers\CourseController;
use App\Http\Controllers\UserController;
use App\Http\Controllers\ZuowenController;
use App\Http\Controllers\PeotryController;
use App\Http\Controllers\DistrictsController;
use App\Http\Controllers\PublicController;
use App\Http\Controllers\RoleController;
use App\Http\Controllers\SchoolController;
use App\Http\Controllers\SchoolUserController;
use App\Http\Controllers\StudentCardController;
use App\Http\Controllers\StudentController;
use App\Http\Controllers\SubjectController;
use App\lib\ShowName;
use App\Models\User;
use App\Notifications\InvoicePaid;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Notification;
use Illuminate\Support\Facades\Route;

Route::post('/login', (new UserController())->login);
Route::post('/user/signup', [UserController::class, "signup"]);
Route::post('/zuowen/info', [ZuowenController::class, "info"]);
Route::post('/peotry/info', [PeotryController::class, "info"]);
Route::get('/city/{parent_id}', [DistrictsController::class, "list"]);


Route::middleware(['auth'])->group(function () {

    Route::get('/zuowen/list', [ZuowenController::class, "list"]);
    Route::get('/peotry/list', [PeotryController::class, "list"]);
    Route::post('/upload/file', [PublicController::class, "upload"]);

    Route::post('/user/signout', [UserController::class, "signout"]);
    Route::post('/user/update', [UserController::class, "update"]);

    Route::post('/school/create', [SchoolController::class, "create"]);
    Route::get('/school/list', [SchoolController::class, "list"]);
    Route::get('/school/campus/simple/list', [CampusController::class, "SimpleList"]);

    Route::middleware(['school'])->group(function () {

        Route::get('/school/campus/list', [CampusController::class, "list"]);
        Route::post('/school/campus/update', [CampusController::class, "update"]);
        Route::post('/school/campus/create', [CampusController::class, "create"]);

        Route::middleware(['campus'])->group(function () {

            Route::get('/user/info', [UserController::class, "info"]);

            Route::get('/teacher/list', [SchoolUserController::class, "list"]);
            Route::post('/teacher/create', [SchoolUserController::class, "create"]);
            Route::post('/teacher/update', [SchoolUserController::class, "update"]);

            Route::post('/class/create', [ClasssController::class, "create"]);
            Route::post('/class/update', [ClasssController::class, "update"]);
            Route::get('/class/info', [ClasssController::class, "info"]);
            Route::get('/class/list', [ClasssController::class, "list"]);
            Route::get('/class/simple/list', [ClasssController::class, "simpleList"]);

            Route::get('/class/member/list', [ClassMemberController::class, "list"]);
            Route::post('/class/member/create', [ClassMemberController::class, "create"]);
            Route::post('/class/member/leave', [ClassMemberController::class, "leave"]);

            Route::post('/subject/create', [SubjectController::class, "create"]);
            Route::post('/subject/update', [SubjectController::class, "update"]);
            Route::get('/subject/list', [SubjectController::class, "list"]);

            Route::get('/student/list', [StudentController::class, "list"]);
            Route::post('/student/create', [StudentController::class, "create"]);
            Route::post('/student/update', [StudentController::class, "update"]);
            Route::get('/student/course', [StudentController::class, "course"]);

            Route::get('/student/info/{id}', [StudentController::class, "info"]);
            Route::post('/student/attendance', [StudentController::class, "attendance"]);
            Route::get('/student/attendance/list', [StudentController::class, "AttendanceList"]);
            Route::post('/student/card/add', [StudentCardController::class, "create"]);

            Route::get('/card/list', [CardController::class, "list"]);
            Route::get('/card/simple/list', [CardController::class, "simpleList"]);
            Route::post('/card/create', [CardController::class, "create"]);
            Route::post('/card/update', [CardController::class, "update"]);
            Route::get('/card/{id}', [CardController::class, "info"]);

            Route::get('/course/list', [CourseController::class, "list"]);
            Route::post('/course/check', [CourseController::class, "check"]);
            Route::post('/course/add', [CourseController::class, "create"]);

            Route::get('/role/list', [RoleController::class, "roleList"]);
            Route::post('/role/update', [RoleController::class, "roleUpdate"]);
            Route::post('/role/create', [RoleController::class, "roleCreate"]);
            Route::post('/role/delete', [RoleController::class, "roleDelete"]);
            Route::get('/power', [RoleController::class, "power"]);
            Route::post('/role/power/update', [RoleController::class, "rolePowerUpdate"]);

        });

    });

});

Route::get('/test/{id}', function (Request $request, ShowName $sm, $id){
    $name = $request->name . $id;
    return $sm->show($name);
});

Route::get('/test/1', function (){
    return SN::show("penglin");
});

Route::get('/send', function () {
    // $user = User::all();
    $user = User::find(1);
    // $user->notify(new InvoicePaid()); // 单人

    $TestEvent = new TestEvent('penglin');     //自定义
    event($TestEvent);

    // Notification::send($user, new InvoicePaid()); // 全部
    return $user;
});


Route::get('/read/{id}', function ($id) {

    $user = User::find($id);

    $user->unreadNotifications->markAsRead();

    return $user;
});
